package homework5.exp1;

import java.io.*;
import java.net.Socket;

/**
 * @author fengq
 */
public class SocketClient {
    public void setClient(){
        try {
            Socket socket=new Socket("localhost",8800);
            OutputStream outputStream = socket.getOutputStream();
            InputStream inputStream = socket.getInputStream();
            ObjectOutputStream objectOutputStream=new ObjectOutputStream(outputStream);
            User user=new User();
            user.setLoginName("Tom");
            user.setPassword("123456");
            objectOutputStream.writeObject(user);
            socket.shutdownOutput();
            String reply=null;
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            while(!((reply=bufferedReader.readLine())==null)){
                System.out.println("我是客户端，服务器的响应为："+reply);
            }
            outputStream.close();
            inputStream.close();
            bufferedReader.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new SocketClient().setClient();
    }
}
